import React from 'react';

import { Profile as Component } from '@/pagesComponents/Profile';
import { ProfileTabVariants } from '@/shared/interfaces';
import { generateMetaData } from '@/shared/lib/meta';
import { getProfileTabs } from '@/shared/lib/profileTab';
import { GetServerSideProps } from 'next';
import Head from 'next/head';

export default function Profile({ tabId }: { tabId: ProfileTabVariants }) {
  const tab = getProfileTabs().find((_tab) => _tab.id === tabId)?.title || 'Профиль';
  return (
    <>
      <Head>{generateMetaData({ title: tab })}</Head>
      <Component tab={tabId} />
    </>
  );
}
export const getServerSideProps: GetServerSideProps = async (context) => {
  const tabId = context.params?.tab as string;
  const isCorrectVariant = tabId !== 'logout' && !!getProfileTabs()?.some((v) => v.id === tabId);
  if (!isCorrectVariant) {
    return {
      notFound: true,
    };
  }
  return {
    props: { tabId },
  };
};
